package ch11;

import java.util.ArrayList;
import java.util.List;

class _02_ArrayListEx2 {
	public static void main(String[] args) {
		final int LIMIT = 10;
		String source = "0123456789abcdefghijABCDEFGHIJ!@#$%^&*()ZZZ";
		int length = source.length(); //length=43		

		List<String> list = new ArrayList<String>(length / LIMIT + 1);

		for (int i = 0; i < length; i += LIMIT) {
			if (i + LIMIT < length)
				list.add(source.substring(i, i + LIMIT));
			else
				list.add(source.substring(i));
		}

		for (int i = 0; i < list.size(); i++) 
			System.out.println(list.get(i));
		System.out.println();
		
		for(String tmp:list) System.out.println(tmp);
		
		/*
		0123456789
		abcdefghij
		ABCDEFGHIJ
		!@#$%^&*()
		ZZZ
		
		0123456789
		abcdefghij
		ABCDEFGHIJ
		!@#$%^&*()
		ZZZ
		*/
	}
}